import org.apache.activemq.security.AuthorizationEntry;
import org.apache.activemq.security.AuthorizationPlugin;
import org.apache.activemq.security.DefaultAuthorizationMap;
import org.apache.activemq.security.TempDestinationAuthorizationEntry;

import com.unknown.AuthenticationPlugin;

// Place your Spring DSL code here
beans = {
	def authorizationMap = new DefaultAuthorizationMap();
	authorizationMap.authorizationEntries = [
		new AuthorizationEntry(topic:'chat', read:'ROLE_ADMIN,ROLE_SYSTEM', write:'ROLE_ADMIN,ROLE_SYSTEM', admin:'ROLE_SYSTEM'),
		new AuthorizationEntry(topic:'ActiveMQ.Advisory.>', read:'ROLE_ADMIN,ROLE_SYSTEM', write:'ROLE_ADMIN', admin:'ROLE_ADMIN')
	]
	authorizationMap.tempDestinationAuthorizationEntry = new TempDestinationAuthorizationEntry(read:"ROLE_SYSTEM", write:"ROLE_SYSTEM", admin:"ROLE_SYSTEM")
	def authorizationPlugin = new AuthorizationPlugin(authorizationMap);
	
	jmsBroker(org.apache.activemq.xbean.XBeanBrokerService) {
		useJmx = true
		persistent = false
		transportConnectors = [
			new org.apache.activemq.broker.TransportConnector(uri: new URI("nio://0.0.0.0:61616"))
			,new org.apache.activemq.broker.TransportConnector(new com.unknown.WSTransportServer(new URI("ws://0.0.0.0:61614")))
		]
		plugins = [
			new AuthenticationPlugin(),
			authorizationPlugin
		]
	}

	jmsConnectionFactory(org.springframework.jms.connection.SingleConnectionFactory) {
		targetConnectionFactory = { org.apache.activemq.ActiveMQConnectionFactory cf ->
			brokerURL = 'vm://localhost'
		}
	}

	defaultJmsTemplate(org.springframework.jms.core.JmsTemplate) { 
		connectionFactory = ref("jmsConnectionFactory") 
	}
	
	chatTopic(org.apache.activemq.command.ActiveMQTopic){
		physicalName = "chat"
	}
	passthruMessageConverter(com.unknown.PassthruMessageConverter){}
	
	/*
	//Mongo DB
	mongoFactory(org.springframework.data.document.mongodb.MongoFactoryBean){
		host = "localhost"
	}
	groovyMongoConverter(com.unknown.GroovyMongoConverter)
			
	//Mongo Template
	mongoTemplate(org.springframework.data.document.mongodb.MongoTemplate, ref("mongoFactory"), "mud", "Room", ref("groovyMongoConverter")){}
			
	xmlns mongo:"http://www.springframework.org/schema/data/mongo"
	mongo.'repositories'('base-package':'com.unknown.domain.repository', 'mongo-template-ref':'mongoTemplate')
	
	persistenceExceptionTranslationPostProcessor(org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor)
	*/
}
